﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using BO.Management.QueryBuilder;

namespace BO.Management
{
    /// <summary>
    /// Base class to manage objects of kind content in Business Object as Report, Folder, Hyperlink.....
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public abstract class BaseInfoObjectProvider<T> : BaseObjectProvider<T> where T : CrystalDecisions.Enterprise.InfoObject
    {

        /// <summary>
        /// Root object ID for all content Object is 23 : the root folder
        /// </summary>
        private const Int32 ROOT_CONTENT_ID = 23;

        public override int RootParentId
        {
            get { return ROOT_CONTENT_ID; }
        }

        /// <summary>
        /// Default constructor must have the logon provider to manage a connection to the cms
        /// </summary>
        /// <param name="logon"></param>
        public BaseInfoObjectProvider(LogonProvider logon) : base(logon) 
        {
            this.AddSpecificFilter();            
        }


        /// <summary>
        /// Add a specific filter. Used to special provider such as Instance, ReccuringInstance
        /// </summary>
        public virtual void AddSpecificFilter()
        {
            this.AddFilterToInstance(false);
        }

        /// <summary>
        /// Add a filter to have instance or not
        /// </summary>
        /// <param name="value"></param>
        public void AddFilterToInstance(Boolean value)
        {
            this.QueryBuilder.AddParameter<Int32>(InfoStoreFieldNames.Instance, OperatorType.Equal, value ? 1:0 );
        }

        /// <summary>
        /// Get the info store table name used to query objects
        /// </summary>
        public override string Query_Table
        {
            get { return "CI_INFOOBJECTS"; }
        }


        public void ScheduleReport(T report)
        {
            this.InfoStore.Schedule(report.ParentInfoObjects);
        }

    }
}
